var prefix = "/server/everytwohoursproduction"
var myChart = null;
var chartDiv = document.getElementById('chart_div');
$(function () {
    load();
});
var myChartContainer = function () {
    chartDiv.style.width = (window.innerWidth - 30) + 'px';
    chartDiv.style.height = (window.innerHeight) + 'px';
};

function load() {
    myChartContainer();
    myChart = echarts.init(chartDiv);
    // myChart = echarts.init(chartDiv, null, {renderer: 'svg'});

    // 指定图表的配置项和数据
// 显示标题，图例和空的坐标轴
    myChart.setOption({
        title: {
            text: 'test'
        },
        toolbox: {
            feature: {

                // dataZoom: {
                //     yAxisIndex: 'none'
                // },
                saveAsImage: {},
                restore: {}
            }
        },
        tooltip: {},
        legend: {
            data: ['']
        },
        xAxis: {
            data: []
        },
        yAxis: {},
        series: [{
            name: '',
            type: 'line',
            data: []
        }]
    });

// 异步加载数据
    $.get('/server/everytwohoursproduction/getList/' + $('#aid').val()).done(function (data) {
        myChart.hideLoading();
        // 填入数据
        myChart.setOption({
            title: {
                text: data.kpName
            },
            xAxis: {
                data: data.keys
            },
            tooltip: {//悬浮条，待改
//                trigger: 'axis',
//                axisPointer: {
//                    animation: true
//                }
            },
            dataZoom: [
                {
                    xAxisIndex: 0     // 表示这个 dataZoom 组件控制 第1个 xAxis
                }
            ],
            series: [{
                // 根据名字对应到相应的系列
                name: data.kpName,
                data: data.values
            }]
        });
    });
}

// function reload() {
//     $("#chart_div").css("width", "100%");
//     $("#chart_div").css("height", "100%");
//     load();
// }

//浏览器大小改变时重置大小
window.onresize = function () {
    myChartContainer();
    myChart.resize();
};
